package com.wench.design.pattern.iterator;

/**
 * @author wench
 */
public class IteratorClient {

    public static void main(String[] args) {
        //  创建聚合对象
        StudentAggregate aggregate = new StudentAggregateImpl();
        //  添加元素
        aggregate.addStudent(new Student("wench", "001"));
        aggregate.addStudent(new Student("fiona", "002"));
        aggregate.addStudent(new Student("mary", "003"));
        aggregate.addStudent(new Student("jerry", "004"));
        aggregate.addStudent(new Student("tom", "005"));
        //  遍历聚合对象
        // 1、获取迭代器对象
        StudentIterator stuIterator = aggregate.getStudentIterator();
        // 2、遍历
        while (stuIterator.hashNext()) {
            System.out.println(stuIterator.next().toString());
        }
    }
}
